const state = {
  loading: false,
  loadingCount: 0
};

const mutations = {
  AJAX_REQUEST(state) {
    state.loadingCount++;
    // console.log(state.loadingCount)
    state.loading = true;
  },
  AJAX_RESPONSE(state, status = true) {
    state.loadingCount--;
    if (state.loadingCount === 0 || !status) {
      state.loading = false;
      state.loadingCount = 0;
    }
    // console.log(state.loadingCount)
  }
};

const actions = {};

const getters = {
  loading: state => state.loading.default
};

export default {
  state,
  mutations,
  actions,
  getters
};
